﻿#ifndef STATISTICSANALYZE_H
#define STATISTICSANALYZE_H

//////////////////////////////////////////////////////////////////////////
// HEX和图表对话框 [12/8/2016 ejitec]
#include <QPoint>
#include <QDialog>

namespace Ui
{
	class diagram;
}

class RIOManager
{
public:

	explicit RIOManager(QPoint& start, QPoint& end, int w, int h, int nDepth, uchar* buf);
	~RIOManager();

	QRect GetSubRIO()
	{
		return QRect(_startP, _endP);
	}
	bool IsRIOFull()
	{
		return ((rio_rows == _lines) && (rio_columns == _columns));
	}

	//x, y is coords of sub RIO
	int GetRIOValue(int x, int y){
		if (x < 0 || x > rio_columns || y < 0 || y > rio_rows)
			return -1;
		int index = (y + _startP.y()) * _columns + (x + _startP.x());
		if (_bit_width == 8)
			return _buf[index];
		else
			return ((unsigned short*)_buf)[index];
	}
	//x, y is coords of orig buf
	int GetValue(int x, int y)
	{
		if (x < 0 || x > _columns || y < 0 || y > _lines)
			return -1;
		int index = y  * _columns + x;
		if (_bit_width == 8)
			return _buf[index];
		else
			return ((unsigned short*)_buf)[index];
	}
	//return full buffer
	unsigned char *GetBuffer() { return _buf; }

	int GetRIORows() { return rio_rows; }
	int GetRIOCols() { return rio_columns; }
	int GetRIOBitWidth() { return _bit_width; }
private:
	int rio_rows;
	int rio_columns;
	int _lines;
	int _columns;
	int _bit_width;
	unsigned char *_buf;
	QPoint _startP;
	QPoint _endP;
};

#if 1

class StatisticsAnalyze : public QDialog
{
	Q_OBJECT

public:
	StatisticsAnalyze(QWidget *parent, QPoint& start, QPoint& end, int w, int h, int nDepth, uchar* buf);
	StatisticsAnalyze(QWidget *parent);
	~StatisticsAnalyze();
	void LoadTestDiagram();

private:
	Ui::diagram* ui;
	RIOManager* _RIO;

	int min;
	int max;
	int avg;
	int var;

	unsigned int *diagram;

	int max_x;
	int max_y;
	QString title;
	QVector<double> x_coord;
	QVector<double> y_coord;
};
#endif

#endif // STATISTICSANALYZE_H
